﻿using System;
using HslCommunication.ModBus;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Inovance
{
	/// <summary>
	/// 汇川的串口通信协议，适用于AM400、 AM400_800、 AC800 等系列，底层走的是MODBUS-RTU协议，地址说明参见标记<br />
	/// Huichuan's serial communication protocol is applicable to AM400, AM400_800, AC800 and other series. The bottom layer is MODBUS-RTU protocol. For the address description, please refer to the mark
	/// </summary>
	/// <remarks>
	/// <inheritdoc cref="T:HslCommunication.Profinet.Inovance.InovanceAMTcp" path="remarks" />
	/// </remarks>
	// Token: 0x02000093 RID: 147
	public class InovanceAMSerial : ModbusRtu
	{
		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.#ctor" />
		// Token: 0x06000B25 RID: 2853 RVA: 0x0001A8CC File Offset: 0x00018ACC
		public InovanceAMSerial()
		{
		}

		/// <summary>
		/// 指定服务器地址，端口号，客户端自己的站号来初始化<br />
		/// Specify the server address, port number, and client's own station number to initialize
		/// </summary>
		/// <param name="station">客户端自身的站号</param>
		// Token: 0x06000B26 RID: 2854 RVA: 0x0001A8D6 File Offset: 0x00018AD6
		public InovanceAMSerial(byte station = 1) : base(station)
		{
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Read(System.String,System.UInt16)" />
		// Token: 0x06000B27 RID: 2855 RVA: 0x00042554 File Offset: 0x00040754
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 3);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Read(operateResult.Content, length);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Byte[])" />
		// Token: 0x06000B28 RID: 2856 RVA: 0x00042594 File Offset: 0x00040794
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 16);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000B29 RID: 2857 RVA: 0x000425D4 File Offset: 0x000407D4
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 1);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.ReadBool(operateResult.Content, length);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Boolean[])" />
		// Token: 0x06000B2A RID: 2858 RVA: 0x00042614 File Offset: 0x00040814
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 15);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, values);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Boolean)" />
		// Token: 0x06000B2B RID: 2859 RVA: 0x00042654 File Offset: 0x00040854
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 5);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.Int16)" />
		// Token: 0x06000B2C RID: 2860 RVA: 0x00042694 File Offset: 0x00040894
		[HslMqttApi("WriteInt16", "")]
		public override OperateResult Write(string address, short value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Inovance.InovanceAMTcp.Write(System.String,System.UInt16)" />
		// Token: 0x06000B2D RID: 2861 RVA: 0x000426D4 File Offset: 0x000408D4
		[HslMqttApi("WriteUInt16", "")]
		public override OperateResult Write(string address, ushort value)
		{
			OperateResult<string> operateResult = InovanceHelper.PraseInovanceAMAddress(address, 6);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				result = base.Write(operateResult.Content, value);
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000B2E RID: 2862 RVA: 0x00042711 File Offset: 0x00040911
		public override string ToString()
		{
			return string.Format("InovanceAMSerial[{0}:{1}]", base.PortName, base.BaudRate);
		}
	}
}
